Interactive Widgets in IJulia

IPython 2.0 introduced interactive widgets, which are basically:

  • Javascript widgets (sliders, buttons, etcetera)
  • A communications protocol for the widgets to talk to the kernel
  • A Python interface to create and manipulate these.

Thanks to fantastic work by a Google Summer of Code student, Shashi Gowda, the same features are accessible from a Julia interface.


In [1]:
using Interact



In [2]:
@manipulate for n in 1:100
    rand(n,n)
end


Out[2]:
50x50 Array{Float64,2}:
 0.2744     0.658081   0.357268   …  0.640755   0.858389   0.408651  
 0.906766   0.0913524  0.603772      0.675245   0.311778   0.274435  
 0.238604   0.708858   0.124889      0.327806   0.728642   0.217951  
 0.711844   0.70349    0.182912      0.636855   0.0936324  0.460768  
 0.905727   0.346835   0.371355      0.0482039  0.210374   0.590046  
 0.981977   0.25433    0.556125   …  0.747529   0.0734597  0.826081  
 0.129242   0.0933683  0.0760227     0.941142   0.479988   0.628485  
 0.882593   0.363313   0.538152      0.0362779  0.563293   0.69553   
 0.0628573  0.645625   0.923794      0.198154   0.691527   0.209142  
 0.581882   0.686953   0.390823      0.174112   0.461502   0.43817   
 0.590119   0.195076   0.65873    …  0.705743   0.428541   0.862039  
 0.735897   0.860987   0.120992      0.154482   0.850719   0.88409   
 0.882374   0.073021   0.99751       0.0586557  0.960649   0.00816542
 ⋮                                ⋱                                  
 0.278727   0.300248   0.457287      0.098932   0.761305   0.170335  
 0.90746    0.546239   0.391356      0.0876562  0.138678   0.709259  
 0.757039   0.308963   0.119933   …  0.814034   0.630751   0.78001   
 0.230828   0.0816324  0.917582      0.77037    0.386126   0.109342  
 0.268848   0.0564709  0.877773      0.599512   0.127713   0.617626  
 0.810549   0.229789   0.481857      0.408747   0.39164    0.868029  
 0.619333   0.313504   0.269523      0.535859   0.600094   0.645821  
 0.386608   0.436052   0.251858   …  0.417625   0.941966   0.859877  
 0.656229   0.828622   0.432555      0.700044   0.536829   0.48496   
 0.301022   0.597423   0.809439      0.56228    0.0944422  0.576287  
 0.128899   0.0145715  0.381588      0.682359   0.386233   0.657723  
 0.824044   0.954336   0.793416      0.0637182  0.0105523  0.955533  

In [3]:
using Colors
@manipulate for r in 0:0.1:1, g in 0:0.1:1, b in 0:0.1:1, n in 1:100
    linspace(RGB(0.0,0.0,0.0), RGB(r,g,b), n)
end


Out[3]:
50-element Array{ColorTypes.RGB{Float64},1}:
 RGB{Float64}(0.0,0.0,0.0)                  
 RGB{Float64}(0.0102041,0.0102041,0.0102041)
 RGB{Float64}(0.0204082,0.0204082,0.0204082)
 RGB{Float64}(0.0306122,0.0306122,0.0306122)
 RGB{Float64}(0.0408163,0.0408163,0.0408163)
 RGB{Float64}(0.0510204,0.0510204,0.0510204)
 RGB{Float64}(0.0612245,0.0612245,0.0612245)
 RGB{Float64}(0.0714286,0.0714286,0.0714286)
 RGB{Float64}(0.0816327,0.0816327,0.0816327)
 RGB{Float64}(0.0918367,0.0918367,0.0918367)
 RGB{Float64}(0.102041,0.102041,0.102041)   
 RGB{Float64}(0.112245,0.112245,0.112245)   
 RGB{Float64}(0.122449,0.122449,0.122449)   
 ⋮                                          
 RGB{Float64}(0.387755,0.387755,0.387755)   
 RGB{Float64}(0.397959,0.397959,0.397959)   
 RGB{Float64}(0.408163,0.408163,0.408163)   
 RGB{Float64}(0.418367,0.418367,0.418367)   
 RGB{Float64}(0.428571,0.428571,0.428571)   
 RGB{Float64}(0.438776,0.438776,0.438776)   
 RGB{Float64}(0.44898,0.44898,0.44898)      
 RGB{Float64}(0.459184,0.459184,0.459184)   
 RGB{Float64}(0.469388,0.469388,0.469388)   
 RGB{Float64}(0.479592,0.479592,0.479592)   
 RGB{Float64}(0.489796,0.489796,0.489796)   
 RGB{Float64}(0.5,0.5,0.5)                  

In [4]:
using PyPlot

In [5]:
x = linspace(0,10,1000)
clf()
f = figure()
@manipulate for α = 1:0.1:4, β = 1:0.1:4, leg="a funny plot"
    withfig(f) do
        plot(x, cos(α*x + sin(β*x)))
        legend([leg])
    end
end


Out[5]:

In [7]:
using SymPy
x = Sym("x")
@manipulate for n=0:20
    latex(SymPy.diff(sin(x^2), x, n))
end


Out[7]:

In [ ]: